<?php

namespace App\Http\Controllers;

use App\Common\Sql;
use Illuminate\Support\Facades\DB;

class PaiWeiInfo extends Base
{

    public function logic()
    {
        $uid  = $this->uid;
        $row  = DB::table('t_player_info')
            ->where('paiwei_score', '<>', 0)
            ->where('robot_flag', 0)
            ->where('status', 1)
            ->orderBy('paiwei_score', 'desc')
            ->limit(16)
            ->get(['id', 'nick_name', 'avater_url', 'paiwei_score'])
            ->map(function ($value) {
                return (array)$value;
            });
        $data = array();
        for ($i = 0; $i < count($row); $i++) {
            $arr                 = array();
            $arr["uid"]          = (int)$row[$i]["id"];
            $arr["avater_url"]   = (string)$row[$i]["avater_url"];
            $arr["paiwei_score"] = (int)$row[$i]["paiwei_score"];
            $arr["nick_name"]    = $row[$i]["nick_name"];
            $data["rank_list"][] = $arr;
        }

        $row1 = Sql::select('t_player_info',[['id',$uid]]);
        if (count($row1) > 0) {
            $data['uid']          = (int)$uid;
            $data['avater_url']   = $row1[0]['avater_url'];
            $data['gold']         = (int)$row1[0]['gold'];
            $data['nick_name']    = $row1[0]['nick_name'];
            $data['paiwei_score'] = (int)$row1[0]['paiwei_score'];
        }

        return $this->returnData($data);
    }
}
